package org.yanfengying.org.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.yanfengying.org.service.IBaiduAiService;
import org.yanfengying.utils.AjaxResult;
import org.yanfengying.utils.BaiduAuditUtils;

import java.util.Map;
@Service
public class BaiduAiServiceImpl implements IBaiduAiService {
    @Override
    public AjaxResult audit(String text, String imgUrl, String videoUrl) {
        AjaxResult result = AjaxResult.me();
        StringBuffer stringBuffer = new StringBuffer();
        if(!StringUtils.isEmpty(text)){//如果text不为空->调用文本审核方法
            Map<String, Object> map = BaiduAuditUtils.TextCensor(text);
            Boolean success = (Boolean) map.get("success");//获取是否合规的信息
            stringBuffer.append(text+":"+map.get("message"));
            result.setSuccess(success).setMessage(stringBuffer.toString());
        }
        if(!StringUtils.isEmpty(imgUrl)){//如果text不为空->调用文本审核方法
            Map<String, Object> map = BaiduAuditUtils.ImgCensor(imgUrl);
            Boolean success = (Boolean) map.get("success");//获取是否合规的信息
            stringBuffer.append(text+":"+map.get("message"));
            result.setSuccess(success).setMessage(stringBuffer.toString());
        }
        return result;
    }
}
